#include "mainscene.h"
#include "ui_mainscene.h"
#include<QPainter>
#include"mypushbutton.h"
#include<QDebug>
#include<QTimer>
#include<QSound>

MainScene::MainScene(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainScene)
{
    ui->setupUi(this);

    //配置主场景
    //设置固定大小
    setFixedSize(320,588);
    //设置图标
    setWindowIcon(QIcon(":/res/Coin0001.png"));
    //设置标题
    setWindowTitle("翻金币场景");

    //退出按钮实现
    connect(ui->actionquit,&QAction::triggered,[=](){
        this->close();
    });

    //准备开始按钮的音效
    QSound * startSound = new QSound(":/res/TapButtonSound.wav");

    //开始按钮
    MyPushBUtton * starBtn = new MyPushBUtton(":/res/MenuSceneStartButton.png");
    starBtn->setParent(this);
    starBtn->move(this->width() *0.5 - starBtn->width()*0.5,this->height() *0.7);

    chooseScene = new ChooseLevelScene;

    //监听选择关卡的返回按钮的信号
    connect(chooseScene,&ChooseLevelScene::chooseSceneBack,[=](){
        this->setGeometry(chooseScene->geometry());
        chooseScene->hide();
        this->show();
    });


    connect(starBtn,&MyPushBUtton::clicked,[=](){
//        qDebug()<< "点击了开始";
        startSound->play();
        //弹起效果
        starBtn->zoom1();
        starBtn->zoom2();

        //延迟进入到 选择关卡场景中
        QTimer::singleShot(500,this,[=](){
            //设置chooseScene场景位置
            chooseScene->setGeometry(this->geometry());
            //进入到选择关卡
            //自身隐藏
            this->hide();
            //显示选择关卡
            chooseScene->show();
        });

    });

}

void MainScene:: paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/res/PlayLevelSceneBg.png");
    painter.drawPixmap(0,0,320,588,pix);

    //画背景上的图标
    pix.load(":/res/Title.png");
    pix = pix.scaled(pix.width() *0.5,pix.height() * 0.5);
    painter.drawPixmap(10,30,pix);
}


MainScene::~MainScene()
{
    delete ui;
}

